/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dinotrack.domain;

import java.util.LinkedList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author alquad
 */
public class CancionSQL {
    
    Session session;
    
    public CancionSQL()
    {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List buscarCancionesListar()
    {
        List<BuscarCancionesListar> canciones = null;
        
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
//            Query q = session.createQuery ("from buscar_canciones_listar");
            Query q = session.createQuery ("from BuscarCancionesListar");
            canciones = (List<BuscarCancionesListar>)q.list(); 

            for(BuscarCancionesListar aux: canciones)
            {
                System.out.println(aux.getCancion()+" - "+aux.getArtista()+" - "+aux.getAlbum()+" - "+aux.getDuracion());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return canciones;
        }
    
    public Cancion getCancionId(int id){
        Cancion cancion = null;
        
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
//            Query q = session.createQuery ("from buscar_canciones_listar");
            Query q = session.createQuery ("from Cancion where idCancion="+id);
            cancion = (Cancion)q.list().get(0); 

        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return cancion;
    }    
}
